<template>
  <div>
    <div><font style="align-content: center;font-size: 24px">我的付费文章</font></div>
    <div>
      <el-table
        :data="favorities"
        stripe
        style="width: 100%"
        tooltip-effect="dark">
        <el-table-column
          prop="id"
          label="ID"
          width="50">
        </el-table-column>
        <el-table-column
          prop="pic"
          label="文章图片">
          <template slot-scope="scope">
            <el-image
              style="width: 100px; height: 100px"
              :src="scope.row.pic"
              fit="fill"></el-image>
          </template>
        </el-table-column>
        <el-table-column
          prop="articleName"
          label="文章名称">
        </el-table-column>
        <el-table-column
          prop="likeNumber"
          label="点赞数"
          width="100">
        </el-table-column>
        <el-table-column
          prop="price"
          label="文章价格"
          width="100">
        </el-table-column>
        <el-table-column
          prop="createTime"
          label="添加时间">
        </el-table-column>
        <el-table-column
          prop="userName"
          label="作者">
        </el-table-column>
        <el-table-column
          fixed="right"
          label="操作"
          width="180">
          <template slot-scope="scope">
            <el-button type="text" size="small" @click="findArticleById(scope.row.articleId)">查看详情</el-button>
            <el-button type="text" size="small" @click="deleteFavorityArticleById(scope.row.id)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>
  import axios from 'axios';
    export default {
        name: "articleFavority",
        data(){
          return{
            favorities:[]
          }
        },
        methods:{
          findAllFavorites(){
            axios.post('http://localhost:8088/article/findAllFavorites').then(res=>{
              if(res.data.code==0){
                this.favorities=res.data.data;
              }
            })
          },
          findArticleById(id){
            this.$router.push({name:"articleInfo",params:{id:id}});
          },
          deleteFavorityArticleById(id){
            axios.post('http://localhost:8088/article/deleteFavorityArticleById',{id:id}).then(res=>{
              if(res.data.code==0){
                this.findAllFavorites();
              }
            })
          }
        },
        mounted() {
          this.findAllFavorites();
        }
    }
</script>

<style scoped>

</style>
